Conditions | 1 |
Paths | 1 |
Total Lines | 78 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /* globals performance */ |
||
16 | function(data, util) { |
||
17 | let sv = this; |
||
18 | sv.hoverElement = ''; |
||
19 | sv.export = ''; |
||
20 | sv.player = {}; |
||
21 | sv.loading = true; |
||
22 | sv.fasterTicks = false; |
||
23 | sv.toast = []; |
||
24 | sv.isToastVisible = false; |
||
25 | let newElements = []; |
||
26 | let updateFunctions = {}; |
||
27 | sv.reactionsCache = {}; |
||
28 | sv.redoxesCache = {}; |
||
29 | sv.reactions = []; |
||
30 | |||
31 | sv.deleteToast = function() { |
||
32 | sv.toast.shift(); |
||
33 | if (sv.toast.length > 0) { |
||
34 | sv.isToastVisible = true; |
||
35 | util.delayedExec(performance.now(),performance.now(), 2500, () => sv.removeToast()); |
||
36 | } |
||
37 | }; |
||
38 | |||
39 | sv.removeToast = function() { |
||
40 | sv.isToastVisible = false; |
||
41 | util.delayedExec(performance.now(),performance.now(), 350, () => sv.deleteToast()); |
||
42 | }; |
||
43 | |||
44 | sv.addToast = function (t) { |
||
45 | sv.toast.push(t); |
||
46 | if (sv.toast.length === 1) { |
||
47 | sv.isToastVisible = true; |
||
48 | util.delayedExec(performance.now(),performance.now(), 2500, () => sv.removeToast()); |
||
49 | } |
||
50 | }; |
||
51 | |||
52 | sv.init = function() { |
||
53 | sv.hoverElement = ''; |
||
54 | sv.export = ''; |
||
55 | sv.toast = []; |
||
56 | sv.isToastVisible = false; |
||
57 | newElements = []; |
||
58 | }; |
||
59 | |||
60 | sv.hasNew = function(entry) { |
||
61 | return newElements.indexOf(entry) !== -1; |
||
62 | }; |
||
63 | |||
64 | sv.addNew = function(entry) { |
||
65 | newElements.push(entry); |
||
66 | }; |
||
67 | |||
68 | sv.removeNew = function(entry) { |
||
69 | if (newElements.indexOf(entry) !== -1) { |
||
70 | newElements.splice(newElements.indexOf(entry), 1); |
||
71 | } |
||
72 | }; |
||
73 | |||
74 | sv.elementHasNew = function(element) { |
||
75 | let includes = data.elements[element].includes; |
||
76 | for (let key in includes) { |
||
77 | if (sv.hasNew(includes[key])) { |
||
78 | return true; |
||
79 | } |
||
80 | } |
||
81 | return false; |
||
82 | }; |
||
83 | |||
84 | sv.registerUpdate = function(name, func){ |
||
85 | updateFunctions[name] = func; |
||
86 | }; |
||
87 | |||
88 | sv.update = function(player){ |
||
89 | for(let func in updateFunctions){ |
||
90 | updateFunctions[func](player); |
||
91 | } |
||
92 | }; |
||
93 | }]); |
||
94 |